package 动态规划;
//https://www.nowcoder.com/practice/1025ffc2939547e39e8a38a955de1dd3?tpId=46&tqId=29048&tPage=1&rp=1&ru=/ta/leetcode&qru=/ta/leetcode/question-ranking
public class 分割回文串_ii {
    public int minCut (String s) {
        // write code here
        int[] arr = new int[s.length() + 1];
        for (int i = 0 ; i <= s.length() ; i ++){
            arr[i] = i - 1;
        }
        for (int i = 1 ; i <= s.length() ; i ++){
            for (int j = 0 ; j < i ; j ++){
                if (is(s.substring(j , i))){
                    arr[i] = Math.min(arr[i] , arr[j] + 1);
                }
            }
        }
        return arr[s.length()];

    }
    public boolean is (String s){
        for (int i = 0 ; i < s.length() ; i ++){
            if (s.charAt(i) != s.charAt(s.length() - 1 - i)){
                return false;
            }
        }
        return true;
    }
}
